import BaseMonsterSkill from "./BaseMonsterSkill";
import IBaseMonsterSkill from "./IBaseMonsterSkill";
import { MonsterStateType } from "../../MonsterStateType";
import MonsterScript from "../../../component/MonsterScript";




export default class InvincibleSkill extends BaseMonsterSkill implements IBaseMonsterSkill {


    _originMat: Laya.Material;
    _alphaMat: Laya.BlinnPhongMaterial;



    init(target: MonsterScript, skillId) {
        super.init(target, skillId);
        this._alphaMat = new Laya.BlinnPhongMaterial();
        this._alphaMat.albedoColor = new Laya.Vector4(1, 1, 1, 0.4);
        this._alphaMat.renderMode = Laya.BlinnPhongMaterial.RENDERMODE_TRANSPARENT;
        this._originMat = (target.owner as Laya.MeshSprite3D).meshRenderer.sharedMaterial;
    }


    exec() {
        // console.log("StopSkill exec")
        if (this._isSkilling === true) {
            if ((Laya.Browser.now() - this._preExecTime) > this._durationTime) {
                (this._target.owner as Laya.MeshSprite3D).meshRenderer.material = this._originMat;
                this._target.setSkipHit(false);
                this._isSkilling = false;
                this.resetTime();
            }
        }
        else {
            if (this.canExec()) {
                this._isSkilling = true;
                this._target.setSkipHit(true);
                (this._target.owner as Laya.MeshSprite3D).meshRenderer.material = this._alphaMat;
                this._alphaMat.albedoTexture = (this._originMat as Laya.UnlitMaterial).albedoTexture;
                this._preExecTime = Laya.Browser.now();
            }
        }

    }

    reset() {
        super.reset();
        this._target.setSkipHit(false);
        (this._target.owner as Laya.MeshSprite3D).meshRenderer.material = this._originMat;
    }

    destroy(){
        this._alphaMat.destroy();
        this._originMat=null;
        super.destroy();
    }


}